package com.wh.testVolatile;

import java.util.concurrent.TimeUnit;

/**
 * 可见性
 *
 */
public class volatileDemo {
    private volatile  static int num=0;
    public static void main(String[] args) {
        new Thread(()->{  //线程1 可能对主内存的变化可能不知道
            while (num==0){

            }
        },"A").start();
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        num=1;
        System.out.println("end==>"+num);
    }
}
